package com.ivc.trade.action;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cs.framework.common.bo.Message;
import com.cs.framework.ui.web.UI;
import com.cs.framework.web.annotation.Action;
import com.cs.framework.web.annotation.Mapping;
import com.cs.framework.web.handler.Web;
import com.ivc.trade.dto.TradeEnterDto;
import com.ivc.trade.service.TradeEnterService;

/**
 * 交易录入
 * 
 * @author hedongzhou
 * 
 */
@Action("tradeEnter")
public class TradeEnterAction {

	private Log logger = LogFactory.getLog(getClass());

	@Resource
	private TradeEnterService tradeEnterService;

	/**
	 * 进入交易录入页面
	 */
	@Mapping
	public void mainPage() {
		UI.returnPage("trade_te");
	}

	/**
	 * 新增进货信息
	 */
	@Mapping
	public Object saveBuyInfo() {
		TradeEnterDto tradeEnterDto = Web.bind(TradeEnterDto.class);

		try {
			tradeEnterService.saveBuyInfo(tradeEnterDto);

			return new Message("Y", "新增成功");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);

			return new Message("N", e.getMessage());
		}
	}

	/**
	 * 新增销售信息
	 */
	@Mapping
	public Object saveSellInfo() {
		TradeEnterDto tradeEnterDto = Web.bind(TradeEnterDto.class);

		try {
			tradeEnterService.saveSellInfo(tradeEnterDto);

			return new Message("Y", "新增成功");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);

			return new Message("N", e.getMessage());
		}
	}

}
